package com.mrd.gtimpframe.remote;

import com.mrd.gtimpframe.entity.TGenDeclaInspectRule;
import com.mrd.gtimpframe.entity.TGenDeclaPolicyRules;
import com.mrd.util.date.DateUtil;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 规则接口对应模型，用于json转换为对象和将数据模型转换输出
 * 
 * @author han
 *
 */
public class PolicyRulesParam {
  PolicyRules data;// 提醒政策

  public PolicyRules getData() {
    return data;
  }

  public void setData(PolicyRules data) {
    this.data = data;
  }

  /**
   * 对应页面的政策提醒
   * 
   * @author han
   *
   */
  public static class PolicyRules {
    public String pruleId;
    public String policyCode;
    public String status;
    public String eftTimeBegin;
    public String bizSceneId;
    public String noticeMsg;
    public String remark;
    public List<Object> ruleGroups = new ArrayList<Object>();

    private List<Group> listRule = new ArrayList<Group>();// 规则组和规则关系

    public List<Group> getListRule() {
      return listRule;
    }

    public void setListRule(List<Group> listRule) {
      this.listRule = listRule;
    }

    public PolicyRules() {

    }

    /**
     * 数据库实体转换为页面模型
     * 
     * @author han
     * @param rules
     * @return
     */
    public PolicyRules PolicyRules(TGenDeclaPolicyRules rules) {
      PolicyRules rtnPolicyRules = new PolicyRules();
      rtnPolicyRules.setPruleId(rules.getId());
      rtnPolicyRules.setStatus(rules.getStatus());
      Date startTime = rules.getStartTime();
      if (startTime != null) {
        rtnPolicyRules
            .setEftTimeBegin(DateUtil.formatDate(startTime, DateUtil.DEFAULT_FORMAT_TYPE));
      }
      rtnPolicyRules.setBizSceneId(rules.getBizScene());
      rtnPolicyRules.setNoticeMsg(rules.getNoticeMsg());
      rtnPolicyRules.setRemark(rules.getDecript());
      rtnPolicyRules.setPolicyCode(rules.getPolicyCode());
      return rtnPolicyRules;
    }

    public String getPruleId() {
      return pruleId;
    }

    public void setPruleId(String pruleId) {
      this.pruleId = pruleId;
    }

    public String getPolicyCode() {
      return policyCode;
    }

    public void setPolicyCode(String policyCode) {
      this.policyCode = policyCode;
    }

    public String getStatus() {
      return status;
    }

    public void setStatus(String status) {
      this.status = status;
    }

    public String getEftTimeBegin() {
      return eftTimeBegin;
    }

    public void setEftTimeBegin(String eftTimeBegin) {
      this.eftTimeBegin = eftTimeBegin;
    }

    public String getBizSceneId() {
      return bizSceneId;
    }

    public void setBizSceneId(String bizSceneId) {
      this.bizSceneId = bizSceneId;
    }

    public String getNoticeMsg() {
      return noticeMsg;
    }

    public void setNoticeMsg(String noticeMsg) {
      this.noticeMsg = noticeMsg;
    }

    public String getRemark() {
      return remark;
    }

    public void setRemark(String remark) {
      this.remark = remark;
    }

    public List<Object> getRuleGroups() {
      return ruleGroups;
    }

    public void setRuleGroups(List<Object> ruleGroups) {
      this.ruleGroups = ruleGroups;
    }

    /**
     * 转换为数据库对象
     * 
     * @author han
     * @return
     */
    public TGenDeclaPolicyRules PolicyRulesToTGenDeclaPolicyRules() {
      TGenDeclaPolicyRules tGenDeclaPolicyRules = new TGenDeclaPolicyRules();
      tGenDeclaPolicyRules.setId(pruleId);
      tGenDeclaPolicyRules.setStatus(status);
      if (StringUtils.isNotEmpty(eftTimeBegin)) {
        tGenDeclaPolicyRules
            .setStartTime(DateUtil.stringToDate(eftTimeBegin, DateUtil.DEFAULT_FORMAT_TYPE));
      }
      tGenDeclaPolicyRules.setBizScene(bizSceneId);
      tGenDeclaPolicyRules.setNoticeMsg(noticeMsg);
      tGenDeclaPolicyRules.setDecript(remark);
      tGenDeclaPolicyRules.setPolicyCode(policyCode);
      return tGenDeclaPolicyRules;
    }
  }

  /**
   * 对应页面中的细则
   * 
   * @author han
   *
   */
  public static class Rule {
    String ruleId;
    String itemId;
    String matchType;
    String matchVal;
    String combiMethod;

    public Rule() {

    }

    /**
     * 数据校验细则转换为页面模型细则
     * 
     * @author han
     * @param tGenDeclaInspectRule
     * @return
     */
    public Rule TGenDeclaInspectRuleToRule(TGenDeclaInspectRule tGenDeclaInspectRule) {
      Rule rule = new Rule();
      rule.setItemId(tGenDeclaInspectRule.getInspectItemId());
      rule.setMatchType(tGenDeclaInspectRule.getOpetion());
      rule.setRuleId(tGenDeclaInspectRule.getId());
      rule.setMatchVal(tGenDeclaInspectRule.getValue());
      return rule;
    }

    public String getRuleId() {
      return ruleId;
    }

    public void setRuleId(String ruleId) {
      this.ruleId = ruleId;
    }

    public String getItemId() {
      return itemId;
    }

    public void setItemId(String itemId) {
      this.itemId = itemId;
    }

    public String getMatchType() {
      return matchType;
    }

    public void setMatchType(String matchType) {
      this.matchType = matchType;
    }

    public String getMatchVal() {
      return matchVal;
    }

    public void setMatchVal(String matchVal) {
      this.matchVal = matchVal;
    }

    public String getCombiMethod() {
      return combiMethod;
    }

    public void setCombiMethod(String combiMethod) {
      this.combiMethod = combiMethod;
    }

    public TGenDeclaInspectRule ruleToTGenDeclaInspectRule() {
      TGenDeclaInspectRule tGenDeclaInspectRule = new TGenDeclaInspectRule();
      tGenDeclaInspectRule.setInspectItemId(itemId);
      tGenDeclaInspectRule.setOpetion(matchType);
      tGenDeclaInspectRule.setStatus("0");
      tGenDeclaInspectRule.setId(ruleId);
      tGenDeclaInspectRule.setValue(matchVal);
      return tGenDeclaInspectRule;
    }
  }

  /**
   * 虚拟规则组
   * 
   * @author han
   *
   */
  public static class Group {
    String groupId = "";
    String combiMethod;
    List<Rule> list = new ArrayList<Rule>();

    public Group() {

    }

    public String getCombiMethod() {
      return combiMethod;
    }

    public void setCombiMethod(String combiMethod) {
      this.combiMethod = combiMethod;
    }

    public List<Rule> getList() {
      return list;
    }

    public void setList(List<Rule> list) {
      this.list = list;
    }

    public String getGroupId() {
      return groupId;
    }

    public void setGroupId(String groupId) {
      this.groupId = groupId;
    }

  }
}
